package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.Address;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.vo.AddressVO;
import com.cskaoyan.service.AddressService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Security;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("wx/address")
public class AddressController {

    @Autowired
    AddressService addressService;

    @GetMapping("list")
    public BaseRespVo addressList(){
        List<AddressVO> addressList = addressService.addressList();
        return BaseRespVo.ok(addressList);
    }
    @GetMapping("detail")
    public BaseRespVo addressDetail(Integer id){
        Map<String,Object> map = addressService.addressDetail(id);
        return BaseRespVo.ok(map);
    }
    @PostMapping("save")
    public BaseRespVo saveAddress(@RequestBody Address address){
        int id = addressService.saveAddress(address);
        return BaseRespVo.ok(id);
    }
    @PostMapping("delete")
    public BaseRespVo deleteAddress(@RequestBody Map map){
        Integer id = (Integer) map.get("id");
        int delete = addressService.deleteAddress(id);
        if (delete != 1){
            return BaseRespVo.fail();
        }
        return BaseRespVo.ok();
    }


}
